package com.everydayflash.jiglib.pong {	import flash.text.TextFormat;		import flash.text.TextFieldAutoSize;		import flash.text.TextField;			import jiglib.geometry.JBox;
	import jiglib.physics.RigidBody;
	import jiglib.plugin.papervision3d.Papervision3DPhysics;
	import jiglib.plugin.papervision3d.Pv3dMesh;
	
	import org.papervision3d.core.math.Number3D;
	import org.papervision3d.core.proto.CameraObject3D;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.shaders.GouraudShader;
	import org.papervision3d.materials.shaders.ShadedMaterial;
	import org.papervision3d.materials.shaders.Shader;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.view.BasicView;
	
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;	

	/**	 * @author bartekd	 */	public class PingPong extends BasicView {		private var physics:Papervision3DPhysics;		private var ball:RigidBody;
		private var mouseConstraint:StiffMouseConstraint;		private var racketModel:Racket;		private var racketBox:JBox;		private var light:PointLight3D;				[Embed (source="assets/ball_material.png")]		private var BallTexture:Class;		private var title:TextField;
		public function PingPong() {			stage.quality = StageQuality.MEDIUM;			stage.scaleMode = StageScaleMode.NO_SCALE;			stage.align = StageAlign.TOP_LEFT;			stage.showDefaultContextMenu = false;			stage.stageFocusRect = false;						super(640, 480, true, true);						camera.focus = 200;			camera.zoom = 40;			camera.z = -24000;			camera.y = 10000;			camera.target = new DisplayObject3D();						light = new PointLight3D(false, false);			light.z = 0;			light.y = 1000;			light.x = -300;			scene.addChild(light);			createObjects();						startRendering();						addTitle();		}				private function addTitle():void {			title = new TextField();			title.autoSize = TextFieldAutoSize.LEFT;			title.defaultTextFormat = new TextFormat("Arial", 12, 0xaaaaaa);			addChild(title);			title.htmlText = "JigLibFlash + Papervision3D demo. More info on <a href='http://www.everydayflash.com'>www.everydayflash.com</a>";					title.x = stage.stageWidth - 25 - title.textWidth;			title.y = stage.stageHeight - 25;		}		protected function createObjects():void {			physics = new Papervision3DPhysics(scene, 20);						racketModel = new Racket();			scene.addChild(racketModel);			racketBox = new JBox(new Pv3dMesh(racketModel), 600, 600, 60);			physics.addBody(racketBox);			mouseConstraint = new StiffMouseConstraint(racketModel, new Number3D(0, 0, 1), camera, viewport);						var b:BitmapMaterial = new BitmapMaterial(new BallTexture().bitmapData);			var s:Shader = new GouraudShader(light, 0xffffff, 0x808080);			var pb:MaterialObject3D = new ShadedMaterial(b, s);						ball = physics.createSphere(pb, 60, 16, 16);			ball.y = 1000;			ball.mass = .25;			ball.friction = 0.9;			ball.material.restitution = 8;					}		override protected function onRenderTick(event:Event = null):void {			mouseConstraint.bend = (mouseX - stage.stageWidth / 2) / 8;			physics.step();			super.onRenderTick(event);						if(ball.y < -3000) ball.y += 6000;		}	}}